<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/27
 * Time: 10:31
 */

namespace app\api\model;

class OrderInfoCg extends Base
{
    /**
     * 插入订单明细草稿
     * @param $insert
     * @return int|string
     */
    static function insertOrderInfoCg($insert = []){
        return self::insertGetId($insert);
    }

    /**
     * 插入订单详情草稿
     * @param $data
     * @return array|false|\think\Collection|\think\model\Collection
     * @throws \Exception
     */
    static function saveOrderInfo($data = []){
        return self::insertAll($data);
    }

    /**
     * 更新订单明细草稿
     * @param $where
     * @param $update
     * @return OrderInfoCg
     */
    static function updateOrderInfoCg($where = [], $update = []){
        return self::where($where)->update($update);
    }

    /**
     * 查询单条订单明细草稿
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findOrderInfoCg($where = [], $field = '*'){
        $data = self::where($where)->field($field)->find();
        if($data){
            $data = $data->toArray();
        }
        return $data;
    }

    /**
     * 查询多条订单明细草稿
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectJoinOrderInfoCg($where = [], $field = '*'){
        $data = self::where($where)
            ->join('up_xl x1', 'x1.device_id = oi_xl', 'LEFT')
            ->join('up_xl x2', 'x2.device_id = oi_xh', 'LEFT')
            ->join('up_gz', 'gz_id = oi_gz', 'LEFT')
            ->field($field)
            ->select()
            ->toArray();
        return $data;
    }

    /**
     * 删除订单明细草稿
     * @param $where
     * @return false|int
     */
    static function delOrderInfoCg($where = []){
        return self::where($where)->delete();
    }
}